package com.oa.modules.approvalsec1.controller;
import java.util.*;

import com.oa.modules.approvalsec1.entity.ProjectScheduleEntity;
import com.oa.modules.approvalsec1.service.ProjectScheduleService;
import com.oa.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.oa.common.utils.R;



/**
 * 项目进度表
 *
 * @author jiangwei
 * @email 785297226@qq.com
 * @date 2021-12-14 09:59:36
 */
@RestController
@RequestMapping("projectschedule")
@Api(tags = "项目进度表相关接口")
public class ProjectScheduleController extends AbstractController {
    @Autowired
    private ProjectScheduleService projectScheduleService;

    /**
     * 列表
     */
//    @GetMapping("/list")
//    @ApiOperation(value = "列表")
//    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = projectScheduleService.queryPage(params);
//        return R.ok().put("page", page);
//    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("generator:projectschedule:info")
    @ApiOperation(value = "信息")
    public R info(@PathVariable("id") Integer id){
		ProjectScheduleEntity projectSchedule = projectScheduleService.getById(id);
        return R.ok().put("projectSchedule", projectSchedule);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation(value = "保存")
    @RequiresPermissions("generator:projectschedule:save")
    public R save(@RequestBody ProjectScheduleEntity projectSchedule){
		projectScheduleService.save(projectSchedule);
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改")
    @RequiresPermissions("generator:projectschedule:update")
    public R update(@RequestBody ProjectScheduleEntity projectSchedule){
		projectScheduleService.updateById(projectSchedule);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    @RequiresPermissions("generator:projectschedule:delete")
    public R delete(@RequestBody Integer[] ids){
		projectScheduleService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }
    /**
     * 获取所有进度
     */
//    @GetMapping ("get")
//    @ApiOperation(value = "查询")
//    public R getSchedule(){
//        List<ProjectScheduleEntity> list = projectScheduleService.list();
//        Map map = new HashMap<String,List<ProjectScheduleEntity>>();
//        ArrayList<ProjectScheduleEntity> scheduleEntityArrayList = new ArrayList<>();
//        for (ProjectScheduleEntity projectScheduleEntity : list) {
//            if (projectScheduleEntity.getParentid() ==0){
//                projectScheduleEntity.setList();
//            }
//        }
//        return R.ok().put("schedule",list);
//    }

    /**
     * 获取所有流程节点
     * @return
     */
    @GetMapping("/nav")
    public R nav(){
        ArrayList<Integer> arrayList = new ArrayList<>();
        List<ProjectScheduleEntity> list = projectScheduleService.list();
        for (ProjectScheduleEntity entity : list) {
            arrayList.add(entity.getId());
        }
        List<ProjectScheduleEntity> scheduList = projectScheduleService.getAllScheduleList(arrayList);

        return R.ok().put("scheduList", scheduList);
    }

}
